package io.renren.modules.sys.service.impl;

import io.renren.common.utils.Constant;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.CoupondetailDao;
import io.renren.modules.sys.entity.CoupondetailEntity;
import io.renren.modules.sys.service.CoupondetailService;


@Service("coupondetailService")
public class CoupondetailServiceImpl extends ServiceImpl<CoupondetailDao, CoupondetailEntity> implements CoupondetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String number = (String)params.get("number");
        String statu = (String)params.get("statu");
        String startime = (String)params.get("startime");
        String endtime = (String)params.get("endtime");
        IPage<CoupondetailEntity> page = this.page(
                new Query<CoupondetailEntity>().getPage(params),
                new QueryWrapper<CoupondetailEntity>().like(StringUtils.isNotBlank(number),"orderNum",number)
                        .eq(StringUtils.isNotBlank(statu),"statu",statu)
                        .gt(StringUtils.isNotBlank(startime),"createtime",startime)
                        .lt(StringUtils.isNotBlank(endtime),"createtime",endtime)
                        .apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );

        return new PageUtils(page);
    }

    @Override
    public List<CoupondetailEntity> queryList(Map<String, Object> params){
        Integer id = Integer.parseInt(params.get("id").toString());

        String wxname = "";
        if(params.get("wxname")!=null && !params.get("wxname").equals("")){
            wxname = params.get("wxname").toString();
        }
        String number = null;
        if(params.get("number")!=null && !params.get("number").equals("")){
            number = params.get("number").toString();
        }
        Integer statu = -1;
        if(params.get("statu")!=null && !params.get("statu").equals("")){
            statu = Integer.parseInt(params.get("statu").toString());
        }
        String startime = null;
        if(params.get("startime")!=null && !params.get("startime").equals("")){
            startime = params.get("startime").toString();
        }
        String endtime = null;
        if(params.get("endtime")!=null && !params.get("endtime").equals("")){
            endtime = params.get("endtime").toString();
        }

        List<CoupondetailEntity> coupondetailEntities = baseMapper.getList(id,wxname,number,statu,startime,endtime);
        return coupondetailEntities;
    }

}
